<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名
      completed 是否生效 需要和 isDone的值关联
     -->
    <li :class="{ completed: item.isDone }" v-for="item in list" :key="item.id">
      <div class="view">
        <input class="toggle" type="checkbox" v-model="item.isDone" />
        <label>{{ item.name }}</label>
        <!-- 删除按钮 -->
        <button @click="removeTodo(item.id)" class="destroy"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  name: 'TodoMain',
  props: {
    // list属性
    list: {
      // 类型是 数组
      type: Array
    }
  },
  methods: {
    removeTodo (id) {
      // console.log('removeTodo')
      // console.log('id:', id)
      // 通知父组件
      this.$emit('removeTodo', id)
    }
  }
}
</script>
